package com.rui.study.algorithm.P_单链表反转;

import com.rui.study.algorithm.ListNode;

/**
 * @program: study
 * @description:
 * @author: Yaowr
 * @create: 2019-03-08 07:55
 **/
public class Main {



    public static void main(String[] args) {
        ListNode node1 = new ListNode(1);
        ListNode node2 = new ListNode(2);
        ListNode node3 = new ListNode(3);
        ListNode node4 = new ListNode(4);
        node1.next = node2;
        node2.next = node3;
        node3.next = node4;

        System.out.println(print(node1));

//        Solution solution = new Solution();
//        Solution_2 solution = new Solution_2();
//        Solution_3 solution = new Solution_3();
        Solution_4 solution = new Solution_4();
        System.out.println(print(solution.reverseList(node1)));

    }

    public static String print(ListNode head) {
        if (head == null) {
            return "";
        }
        String nextVal = print(head.next);
        if (nextVal.length() > 0) {
            nextVal = "->" + nextVal;
        }
        return head.val + nextVal;
    }
}
